Page({
  data: {
    goodsList: [{
        imgUrl: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg3.tbcdn.cn%2Ftfscom%2Fi2%2F1777552687%2FTB261xfoVXXXXa.XpXXXXXXXXXX_%21%211777552687.png&refer=http%3A%2F%2Fimg3.tbcdn.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg",
        name: '辣条',
        price: 2
      },
      {
        imgUrl: "https://img1.baidu.com/it/u=132878754,2740809886&fm=26&fmt=auto&gp=0.jpg",
        name: '腊肉',
        price: 5
      },
      {
        imgUrl: "https://img0.baidu.com/it/u=2052582267,4257862903&fm=26&fmt=auto&gp=0.jpg",
        name: '小白菜',
        price: 1
      }
    ]
  },
  // 云开发支付
  goPay(e) {
    console.log(e.currentTarget.dataset.item, '点击购买')
    let good = e.currentTarget.dataset.item
    wx.cloud.callFunction({
      name: 'pay',
      data: {
        //动态传递商品名称及商品价格
        goodsName: good.name,
        totalFee: good.price
      },
      success: res => {
        console.log(res, '获取支付参数ok')
        const payment = res.result.payment

        //调取支付
        wx.requestPayment({
          ...payment,
          success(res) {
            console.log('pay success', res)
          },
          fail(err) {
            console.error('pay fail', err)
          }
        })
      },
      fail: console.error,
    })
  }
})